home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kabc / field.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-01-15  |  4.5 KB  |  177 lines

  1. /*
  2.     This file is part of libkabc.
  3.     Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public License
  16.     along with this library; see the file COPYING.LIB.  If not, write to
  17.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.     Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. #ifndef KABC_FIELD_H
  22. #define KABC_FIELD_H
  23.  
  24. #include <qstring.h>
  25. #include <qvaluelist.h>
  26.  
  27. #include "addressee.h"
  28.  
  29. class KConfig;
  30.  
  31. namespace KABC {
  32.  
  33. class KABC_EXPORT Field
  34. {
  35.   class FieldImpl;
  36.   friend class FieldImpl;
  37.  
  38. public:
  39.   typedef QValueList<Field *> List;
  40.  
  41.   /**
  42.    * @li @p All -
  43.    * @li @p Frequent -
  44.    * @li @p Address -
  45.    * @li @p Email -
  46.    * @li @p Personal -
  47.    * @li @p Organization -
  48.    * @li @p CustomCategory -
  49.    */  
  50.   enum FieldCategory
  51.   {
  52.     All = 0x0,
  53.     Frequent = 0x01,
  54.     Address = 0x02,
  55.     Email = 0x04,
  56.     Personal = 0x08,
  57.     Organization = 0x10,
  58.     CustomCategory = 0x20
  59.   };
  60.  
  61.   /**
  62.    * Returns the translated label for this field.
  63.    */
  64.   virtual QString label();
  65.  
  66.   /**
  67.    * Returns the  ored categories the field belongs to.
  68.    */
  69.   virtual int category();
  70.  
  71.   /**
  72.    * Returns the translated label for field category.
  73.    */
  74.   static QString categoryLabel( int category );
  75.  
  76.   /**
  77.    * Returns a string representation of the value the field has in the given
  78.    * Addressee. Returns QString::null, if it is not possible to convert the
  79.    * value to a string.
  80.    */
  81.   virtual QString value( const KABC::Addressee & );
  82.  
  83.   /**
  84.    * Sets the value of the field in the given Addressee. Returns true on success
  85.    * or false, if the given string couldn't be converted to a valid value.
  86.    */
  87.   virtual bool setValue( KABC::Addressee &, const QString & );
  88.  
  89.   /**
  90.    * Returns a string, that can be used for sorting.
  91.    */
  92.   QString sortKey( const KABC::Addressee & );
  93.  
  94.   /**
  95.    * Returns, if the field is a user-defined field.
  96.    */
  97.   virtual bool isCustom();
  98.  
  99.   /**
  100.    * Returns, if the field is equal with @a field.
  101.    */
  102.   virtual bool equals( Field *field );
  103.  
  104.   /**
  105.    * Returns a list of all fields.
  106.    */
  107.   static Field::List allFields();
  108.  
  109.   /**
  110.    * Returns a list of the default fields.
  111.    */
  112.   static Field::List defaultFields();
  113.  
  114.   /**
  115.    * Creates a custom field.
  116.    *
  117.    * @param label    The label for this field
  118.    * @param category The category of this field
  119.    * @param key      Unique key for this field
  120.    * @param app      Unique app name for this field
  121.    */
  122.   static Field *createCustomField( const QString &label, int category,
  123.                                    const QString &key, const QString &app );
  124.  
  125.   /**
  126.    * Delete all fields from list.
  127.    */
  128.   static void deleteFields();
  129.  
  130.   /**
  131.    * Save the field settings to a config file.
  132.    *
  133.    * @param cfg        The config file object
  134.    * @param identifier The unique identifier
  135.    * @param fields     The list of the fields
  136.    */
  137.   static void saveFields( KConfig *cfg, const QString &identifier,
  138.                           const Field::List &fields );
  139.   /**
  140.    * This is the same as above, with the difference, that
  141.    * the list is stored in KGlobal::config() in group "KABCFields".
  142.    */
  143.   static void saveFields( const QString &identifier,
  144.                           const Field::List &fields );
  145.  
  146.   /**
  147.    * Load the field settings from a config file.
  148.    *
  149.    * @param cfg        The config file object
  150.    * @param identifier The unique identifier
  151.    */
  152.   static Field::List restoreFields( KConfig *cfg, const QString &identifier );
  153.  
  154.   /**
  155.    * This is the same as above, with the difference, that
  156.    * the list is loaded from KGlobal::config() from group "KABCFields".
  157.    */
  158.   static Field::List restoreFields( const QString &identifier );
  159.  
  160. protected:
  161.   static void createField( int id, int category = 0 );
  162.   static void createDefaultField( int id, int category = 0 );
  163.  
  164. private:
  165.   Field( FieldImpl * );
  166.   virtual ~Field();
  167.  
  168.   FieldImpl *mImpl;
  169.  
  170.   static Field::List mAllFields;
  171.   static Field::List mDefaultFields;
  172.   static Field::List mCustomFields;
  173. };
  174.  
  175. }
  176. #endif
  177.